home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Why is Gets() so bad?
- Date: Thu, 07 Mar 96 17:55:30 GMT
- Organization: none
- Message-ID: <826221330snz@genesis.demon.co.uk>
- References: <4hb1ie$pa7@ixnews2.ix.netcom.com> <4hdvuv$3vr@gryphon.phoenix.net> <4hl7cp$m84@ns2.ptd.net>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4hl7cp$m84@ns2.ptd.net> onyx@postoffice.ptd.net "Matt Ayres" writes:
-
- >I am still sorta a newbie and I hate gets() for that reason. Could you
- >show me some code to write my own gets() function? It would be much
- >help.
-
- The normal approach is to use fgets() instead which allows you to specify the
- length of the buffer you are passing it. Unlike gets() fgets() writes the
- line terminating '\n' character at the end of the string. If this causes
- problems you'll have to get rid of it yourself. You can however use it to
- test whether you read a full line i.e. your buffer was large enough. It can
- be the basis of an algorithm to read an arbitrarily long line if you wish.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-